﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Dynamic.Core;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using PMS.XCMG.Entity;
using PMS.XCMG.IBusiness;
using PMS.XCMG.Util;
using PMS.XCMG.Models;

namespace PMS.XCMG.Business
{
    public class CF_ConfigBusiness : BusRepository<CF_Config>, ICF_ConfigBusiness, IScopedDependency
    {
        private IServiceProvider SvcProvider { get; set; }
        public CF_ConfigBusiness(GDbContext context, IServiceProvider svcProvider)
            : base(context)
        {
            this.SvcProvider = svcProvider;
        }

        public Task<PageResult<CF_Config>> GetPageResultAsync(PageInput<CF_ConfigQM> query)
        {
            var queryable = this.GetQueryable(true);
            var search = query.Search;
            if (!search.Keyword.IsNullOrEmpty())
                queryable = queryable.Where(w => w.Name.Contains(search.Keyword) || w.Code.Contains(search.Keyword));
            if (!search.Type.IsNullOrEmpty())
                queryable = queryable.Where(w => w.Type == search.Type);

            return this.GetPageResultAsync(queryable, query);
        }
        public Task<CF_Config> GetByCodeAsync(string whseId, string code)
        {
            return this.GetAsync(w => w.CompanyId == whseId && w.Code == code, true);
        }
    }
}
